<div class="block">
<div class="invertedshiftdown">
		
		<ul>
			<li><a href="?page=home">首页</a></li>
			<li><a href="?page=current_user">帐户详情</a></li>
			<li class="current"><a href="?page=contact_user">联络其他用户</a></li>
 		</ul>
		<form id="myform">
			<input type="text" class="textinput" /> <input class="submit" type="submit" value="搜索" />
		</form>
	</div>
	<br style="clear: both;" />
	
<?php
if(isset($_GET['id'])){
	$toid=$_GET['id'];
	$toname="";
	foreach($allUsers as $u){
		if($u->id==$toid){
			$toname=$u->name;
		}
	}
?>
		<style type="text/css">
		body { background-color: #dbe2ed } 
		 
		.message_container { 
		    width: 70%; 
		    margin: 0 auto; 
		} 
		 
		.white-shadow { 
		    background-image: -webkit-linear-gradient(top, rgba(255, 255, 255, .8) 4px, rgba(255, 255, 255, .28) 8px); 
		    background-image: -moz-linear-gradient(top, rgba(255, 255, 255, .8) 4px, rgba(255, 255, 255, .28) 8px); 
		    background-image: -ms-linear-gradient(top, rgba(255, 255, 255, .8) 4px, rgba(255, 255, 255, .28) 8px); 
		    background-image: -o-linear-gradient(top, rgba(255, 255, 255, .8) 4px, rgba(255, 255, 255, .28) 8px); 
		    background-image: -linear-gradient(top, rgba(255, 255, 255, .8) 4px, rgba(255, 255, 255, .28) 8px); 
		    background-image: -webkit-gradient(linear, 0 0, 0 100%, from(rgba(255, 255, 255, .8)) 4px, to(rgba(255, 255, 255, .28)) 8px); 
		    padding: 2px 8px 4px; 
		    margin: 0; 
		    border-radius: 24px; 
		} 
		 
		.text-left { 
		    background-color: #d2d2d2; 
		    background-image: -webkit-linear-gradient(top, #9da0a6, #d2d2d2 17px, #e5e5e5 92%); 
		    border-radius: 15px; 
		    box-shadow: 2px 1px 2px rgba(0, 0, 0, 0.6); 
		    font: 15px Helvetica, Arial, sans-serif; 
		    margin: 1em 51% 1em 0; 
		    padding: 0 4px; 
		    position: relative; 
		    border-width: 1px; 
		    border-color: #9DA0A6 #9DA0A6 #9DA0A6 transparent; 
		    border-style: solid; 
		} 
		 .r{
		 	position: relative; 
	        margin: 1em 0 1em 51%; 
		    padding: 0 4px; 
		 }
		.text-right { 
		    background-color: #a9e24c; 
		    background-image: -webkit-linear-gradient(top, #309b19, #a9e24c 17px, #9bcc45 92%); 
		    border-radius: 15px; 
		    box-shadow: -2px 1px 2px rgba(0, 0, 0, 0.6); 
		    font: 15px Helvetica, Arial, sans-serif; 
		    margin: 1em 0 1em 51%; 
		    padding: 0 4px; 
		    position: relative; 
		    border-width: 1px; 
		    border-color: #309b19 transparent #309b19 #309b19; 
		    border-style: solid; 
		} 
		 
		.text-left:before { 
		    content: ""; 
		    position: absolute; 
		    z-index: -1; 
		    bottom: -1px; 
		    height: 6px; 
		    border-right: 14px solid #d5d5d5; 
		    background: #dbe2ed; 
		    -webkit-border-bottom-right-radius: 36px 18px; 
		    -moz-border-radius-bottomright: 36px 18px; 
		    border-bottom-right-radius: 36px 18px; 
		    box-shadow: 2px 2px 2px #9da0a6; 
		    -webkit-transform: translate(0, -2px); 
		    -moz-transform: translate(0, -2px); 
		    -ms-transform: translate(0, -2px); 
		    -o-transform: translate(0, -2px); 
		    transform: translate(0, -2px); 
		    right: 98%; 
		} 
		 
		.text-left:after { 
		    content: ""; 
		    position: absolute; 
		    z-index: -1; 
		    bottom: 0px; 
		    right: 95.5%; 
		    width: 28px; 
		    height: 12px; 
		    background: #dbe2ed; 
		    -webkit-border-bottom-right-radius: 18px 12px; 
		    -moz-border-radius-bottomright: 18px 12px; 
		    border-bottom-right-radius: 20px 20px; 
		    -webkit-transform: translate(-12px, -2px); 
		    -moz-transform: translate(-12px, -2px); 
		    -ms-transform: translate(-12px, -2px); 
		    -o-transform: translate(-12px, -2px); 
		    transform: translate(-12px, -2px); 
		} 
		 
		.text-right:before { 
		    content: ""; 
		    position: absolute; 
		    z-index: -1; 
		    bottom: -1px; 
		    height: 6px; 
		    border-left: 14px solid #a9e24c; 
		    background: #dbe2ed; 
		    -webkit-border-bottom-left-radius: 36px 18px; 
		    -moz-border-radius-bottomleft: 36px 18px; 
		    border-bottom-left-radius: 36px 18px; 
		    box-shadow: 2px 2px 2px #9da0a6; 
		    -webkit-transform: translate(0, -2px); 
		    -moz-transform: translate(0, -2px); 
		    -ms-transform: translate(0, -2px); 
		    -o-transform: translate(0, -2px); 
		    transform: translate(0, -2px); 
		    left: 98%; 
		} 
		 
		.text-right:after { 
		    content: ""; 
		    position: absolute; 
		    z-index: -1; 
		    bottom: 0px; 
		    left: 103.5%; 
		    width: 28px; 
		    height: 12px; 
		    background: #dbe2ed; 
		    -webkit-border-bottom-left-radius: 20px 12px; 
		    -moz-border-radius-bottomleft: 20px 12px; 
		    border-bottom-left-radius: 20px 20px; 
		    -webkit-transform: translate(-12px, -2px); 
		    -moz-transform: translate(-12px, -2px); 
		    -ms-transform: translate(-12px, -2px); 
		    -o-transform: translate(-12px, -2px); 
		    transform: translate(-12px, -2px); 
		}
		
		.message_container span {
			color: #999;
			line-height: normal;
		}
		</style>
	<div id= 'content'>
	<h2>联络其他用户》与 <?php echo $toname;?> 的联系记录</h2>
<script type="text/javascript">
var refresh=setInterval(function(){messageRefresh()},10000);
function messageRefresh()
{
		var time="2009-01-01 16:04:00";
	if($('div.message_container').children().length>1){
		time=$('div.message_container > p >span').last().text();
	}
  jQuery.ajax({
	  type: "POST",
	  url: "api/",
	  dataType : 'json',
	   
	  data: {action: "new_contact_history",from :<?php echo $currentUser->id?>,to : <?php echo $toid;?>,time:time},
	  success: function(data)          //on recieve of reply
	      {
			var htmlContent="";
	        var position="text-right";
	        var datePosition="r";
	        var htmlrow="";
	      
	        for(var i=0;i<data.length;i++){
	        	if(data[i]['position']=="right"){
	        		datePosition="r";
	        		position="text-right";
	        	}else{
	        		datePosition="l";
	        		position="text-left";
	        	}
	        	
	        	htmlrow= "<p class='"+datePosition+"'><span>"+data[i]['starttime']+"</span></p><div class='"+position+"'><p class='white-shadow'>"+data[i]['content']+"</p></div>";
	        	htmlContent+=htmlrow;
	        }
	  			jQuery('div.message_container').append(htmlContent);
	
	      },
	
	  error: function(){
	  	jQuery('#historyLogger').show();
	  }
});
}
function messageRefreshStop()
{
clearInterval(messageRefresh);
}

function send()
{
	jQuery('#messageLoader').show();

	jQuery('#messageLogger').hide();
	//$('div.message_container > p >span').last().css("border","3px solid red");
	
	var time="2009-01-01 16:04:00";
	if($('div.message_container').children().length>1){
		time=$('div.message_container > p >span').last().text();
	}
	var mes=jQuery("#message").val();
	if(mes==""){
		jQuery('#messageLoader').hide();
		jQuery('#message').val("");
	}else{
	
	jQuery.ajax({
	  type: "POST",
	  url: "api/",
	  dataType : 'json',   
	  data: {action: "contact_send",from :<?php echo $currentUser->id?>,to : <?php echo $toid;?>,message : mes,time :time},
	  success: function(data)          //on recieve of reply
	      {
	        var htmlContent="";
	        var position="text-right";
	        var datePosition="r";
	        var htmlrow="";
	      
	        for(var i=0;i<data.length;i++){
	        	if(data[i]['position']=="right"){
	        		datePosition="r";
	        		position="text-right";
	        	}else{
	        		datePosition="l";
	        		position="text-left";
	        	}
	        	
	        	htmlrow= "<p class='"+datePosition+"'><span>"+data[i]['starttime']+"</span></p><div class='"+position+"'><p class='white-shadow'>"+data[i]['content']+"</p></div>";
	        	htmlContent+=htmlrow;
	        }
	  			jQuery('div.message_container').append(htmlContent);
				jQuery('#messageLoader').hide();
				jQuery('#message').val("");
	      },
	
		  error: function(){
	  		jQuery('#messageLoader').hide();
	  		jQuery('#messageLogger').show();
	 	 }
		});
	}
}


function load(){//start point get all data.
	jQuery.ajax({
	  type: "POST",
	  url: "api/",
	  dataType : 'json',
	   
	  data: {action: "contact_history",from :<?php echo $currentUser->id?>,to : <?php echo $toid;?>},
	  success: function(data)          //on recieve of reply
	      {
	
	        var htmlContent="<img src='images/user/default_mini.png'>";
	        var position="text-right";
	        var datePosition="r";
	        var htmlrow="";
	      
	        for(var i=0;i<data.length;i++){
	        	if(data[i]['position']=="right"){
	        		datePosition="r";
	        		position="text-right";
	        	}else{
	        		datePosition="l";
	        		position="text-left";
	        	}
	        	
	        	htmlrow= "<p class='"+datePosition+"'><span>"+data[i]['starttime']+"</span></p><div class='"+position+"'><p class='white-shadow'>"+data[i]['content']+"</p></div>";
	        	htmlContent+=htmlrow;
	        }
	  			jQuery('div.message_container').html(htmlContent);
	          	jQuery('#historyLoader').hide();
	
	      },
	
	  error: function(){
	  	jQuery('#historyLoader').hide();
	  	jQuery('#historyLogger').show();
	  }
});
}
load();
	</script>
	<?php
	?>
				<center id='historyLoader' style="background-color: #DBE2ED;display: none;"><img src="images/ajax-loader.gif"></center>
				<center id='historyLogger' style="background-color: #DBE2ED;display: none;">		
						<div class="isa_error">
							<h4>未能加载联络历史：</h4>后台错误
						</div>
				</center>
					
				<div class="message_container"> 
		

				</div> 
				<center id='messageLoader' style="background-color: #DBE2ED;display:none"><img src="images/ajax-loader.gif"></center>

				<br>    
		<hr>
		<center id='messageLoader'style="background-color: #DBE2ED">
			<center id='messageLogger' style="background-color: #DBE2ED;display: none;">		
						<div class="isa_error">
							<h4>未能发送出去：</h4>请刷新页面重试
						</div>
				</center>
	        	<textarea id="message" name="message" rows="4" cols="50"></textarea>
	 		       
				<a id="send" href="#" class="button blue" onclick="send()">发送</a>
 		</center>
	</div>
<?php
}else{
?>
	<script>
	function openForm(id){
		
		for(var i=1;i<=5;i++){
			if(i==id){
				jQuery("#form"+i).show();
				jQuery("#tab"+i).addClass("current");
			}else{
				jQuery("#form"+i).hide();
				jQuery("#tab"+i).removeClass();	
			}
		}
	}
</script>
<div id= 'content'>
	<h2>联络其他用户》用户查找</h2>
			<ol id="toc">
				<li id='tab1'class="current"><a href="#form3"><span onclick="openForm('1')">管理员</span></a></li>
				<li id='tab2'><a href="#form1"><span onclick="openForm('2')">仓库</span></a></li>
			    <li id='tab3'><a href="#form2"><span onclick="openForm('3')">商铺</span></a></li>
			    <li id='tab4'><a href="#form3"><span onclick="openForm('4')">财务</span></a></li>
			    <li id='tab5'><a href="#form3"><span onclick="openForm('5')">超级管理员</span></a></li>
			</ol>
	<dd id="form1" style="height:60px">
		<?php
		foreach($allUsers as $u){
			if($u->inDepartment("管理员")&&$u->id!=$currentUser->id){
		?>
						<a href="?page=contact_user&id=<?php echo $u->id;?>" style="float:left; margin-right:40px;"><img src="images/user/default_mini.png"></a>

	<ul>	
<?php
if($user->id==$currentUser->id){
		echo "<li>用户名：<a class='online stat_small' href='?page=contact_user&id=$u->id'>$u->name</a></li>";
		}else{
		 if(in_array($user->id,$online)){
echo "<li>用户名：<a class='online stat_small' href='?page=contact_user&id=$u->id'>$u->name</a></li>";
		 }else{
		 echo "<li>用户名：<a class='offline stat_small' href='?page=contact_user&id=$u->id'>$u->name</a></li>";
		 }
		  }
?>
		
		<li>权限：<?php echo $u->getAuthorityName();?> </li>
		<li>职位：<?php echo $u->position;?> </li>
	</ul>
	<?php
		}
	}
	?>
	</dd>
	<dd id="form2" style="display:none;">
		<?php
		foreach($allUsers as $u){
			if($u->inDepartment("仓库管理员")&&$u->id!=$currentUser->id){
		?>
						<a href="?page=contact_user&id=<?php echo $u->id;?>" style="float:left; margin-right:40px;"><img src="images/user/default_mini.png"></a>

	<ul>	
<?php
if($user->id==$currentUser->id){
		echo "<li>用户名：<a class='online stat_small' href='?page=contact_user&id=$u->id'>$u->name</a></li>";
		}else{
		 if(in_array($user->id,$online)){
echo "<li>用户名：<a class='online stat_small' href='?page=contact_user&id=$u->id'>$u->name</a></li>";
		 }else{
		 echo "<li>用户名：<a class='offline stat_small' href='?page=contact_user&id=$u->id'>$u->name</a></li>";
		 }
		  }
?>
		<li>权限：<?php echo $u->getAuthorityName();?> </li>
		<li>职位：<?php echo $u->position;?> </li>
	</ul>
	<?php
		}
		}	
		?>
	</dd>
	
	<dd id="form3" style="display:none;">
		<?php
		foreach($allUsers as $u){
			if($u->inDepartment("店员")&&$u->id!=$currentUser->id){
		?>
						<a href="?page=contact_user&id=<?php echo $u->id;?>" style="float:left; margin-right:40px;"><img src="images/user/default_mini.png"></a>

	<ul>	

<?php
if($user->id==$currentUser->id){
		echo "<li>用户名：<a class='online stat_small' href='?page=contact_user&id=$u->id'>$u->name</a></li>";
		}else{
		 if(in_array($user->id,$online)){
echo "<li>用户名：<a class='online stat_small' href='?page=contact_user&id=$u->id'>$u->name</a></li>";
		 }else{
		 echo "<li>用户名：<a class='offline stat_small' href='?page=contact_user&id=$u->id'>$u->name</a></li>";
		 }
		  }
?>
		<li>权限：<?php echo $u->getAuthorityName();?> </li>
		<li>职位：<?php echo $u->position;?> </li>
	</ul>
	<?php	
			}
		}
		?>
	</dd>
	
	<dd id="form4" style="display:none;">
		<?php
		foreach($allUsers as $u){
						if($u->inDepartment("会计")&&$u->id!=$currentUser->id){
			
		?>
	<a href="?page=contact_user&id=<?php echo $u->id;?>" style="float:left; margin-right:40px;"><img src="images/user/default_mini.png"></a>
	<ul>	

<?php
if($user->id==$currentUser->id){
		echo "<li>用户名：<a class='online stat_small' href='?page=contact_user&id=$u->id'>$u->name</a></li>";
		}else{
		 if(in_array($user->id,$online)){
echo "<li>用户名：<a class='online stat_small' href='?page=contact_user&id=$u->id'>$u->name</a></li>";
		 }else{
		 echo "<li>用户名：<a class='offline stat_small' href='?page=contact_user&id=$u->id'>$u->name</a></li>";
		 }
		  }
?>
		<li>权限：<?php echo $u->getAuthorityName();?> </li>
		<li>职位：<?php echo $u->position;?> </li>
	</ul>
	<?php
						}
	
		}
		?>
	</dd>
	
	<dd id="form5" style="display:none;">
		<?php
		foreach($allUsers as $u){
									if($u->inDepartment("超级管理员")&&$u->id!=$currentUser->id){
			
		?>
		
				<a href="?page=contact_user&id=<?php echo $u->id;?>" style="float:left; margin-right:40px;"><img src="images/user/default_mini.png"></a>
		<ul>
<?php
if($user->id==$currentUser->id){
		echo "<li>用户名：<a class='online stat_small' href='?page=contact_user&id=$u->id'>$u->name</a></li>";
		}else{
		 if(in_array($user->id,$online)){
echo "<li>用户名：<a class='online stat_small' href='?page=contact_user&id=$u->id'>$u->name</a></li>";
		 }else{
		 echo "<li>用户名：<a class='offline stat_small' href='?page=contact_user&id=$u->id'>$u->name</a></li>";
		 }
		  }
?>
		<li>权限：<?php echo $u->getAuthorityName();?> </li>
		<li>职位：<?php echo $u->position;?> </li>
	</ul>
	<?php
									}
		}
		?>
	</dd>

<br>

<hr>

</div>

	<?php
	}
	?>
	<div class="clear"></div>
	</div>